package com.sun.common.excetion;

import com.sun.common.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle<T> {

    @ExceptionHandler(BusinessException.class)
    public Result<T> resolveBusinessException(BusinessException be) {
        log.warn(be.getMessage(), be);
        return new Result<>(be.getErrorCode(), be.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public Result<T> resolveException(Exception e) {
        log.error(e.getMessage(), e);
        return new Result<>(e.getMessage());
    }

}
